//
//  Statistics.hpp
//  sad
//
//  Created by Christopher Kemsley on 3/21/12.
//  Copyright (c) 2012 iAppolopolis. All rights reserved.
//

#ifndef sad_Statistics_hpp
#define sad_Statistics_hpp

#include "SystemCDefinitions.hpp"
#include <map>
#include <string>
#include "Log.hpp"


#define	StatsNamespaceBegin	namespace Stats {
#define	StatsNamespaceEnd	}



StatsNamespaceBegin




enum {
	kRetroactive	=	true ,
	kNonRetroactive	=	false
} ;




template <typename Type>
struct	Value
{
	Value	( std::string const & name , Type const & initialValue = 0 ) ;
	~Value	() ;
	
	
	
	Type const&	value () const ;
	void		setValue ( Type const & value , bool retroactive=kNonRetroactive ) ;
	
	// non retroactive
	void		operator=	( Type const & value ) ;
	bool		operator!=	( Type const & value ) const ;
	bool		operator==	( Type const & value ) const ;
	
private:
	std::string const	mName ;
	Type				mValue ;
	SCInterval			mTime ;
	std::map<Type,SCInterval>	mRecord ;
} ;





template <typename Type>
struct	Accumulator
{
	Accumulator ( std::string const & name , std::string const & unit = "Values"/* per second */ ) ;
	~Accumulator () ;
	
	void	operator +=	( Type const & value ) ;
	
	
private:
	std::string const	mName ;
	Type				mValue ;
	std::string const	mUnits ;
	SCInterval			mStartTime ;
} ;




#include "Statistics.hxx"
StatsNamespaceEnd

#endif
